
import glob
from PIL import Image


def show_upload():
    """
    显示图片上传
    :return:
    """
    return glob.glob("static/upload/*")


def show_thumbs():
    """
    显示缩略图
    :return:
    """
    return glob.glob("static/thumbs/*")


def save_upload(img_file):
    """
    upload 保存
    :param img_file:
    :return:
    """
    save_to = "static/upload/{}".format(img_file["filename"])
    with open(save_to, "wb") as f:
        f.write(img_file["body"])
    return save_to


def save_thumbs(save_to, img_name):
    """
    缩略图保存
    :param save_to:
    :param img_name:
    :return:
    """
    im = Image.open(save_to)
    im.thumbnail((200, 200))
    path = "static/thumbs/{}".format(img_name)
    im.save(path)
    return path

